home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 5535 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Unable to check calloc`s
  5. Date: 08 Feb 1996 15:37:25 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb8083725@qcd.lanl.gov>
  8. References: <4f2l8a$c98@gail.ripco.com> <4fadmp$t6g@osage.csc.ti.com>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: ramli@sislnews.csc.ti.com's message of 7 Feb 1996 08:41:29 -0600
  13.  
  14. In article <4fadmp$t6g@osage.csc.ti.com> ramli@sislnews.csc.ti.com
  15. (C. S. Ramalingam) writes: 
  16. <snip>
  17.    When would using calloc be more appropriate than using malloc ?  Is it true
  18.    that the only use for calloc is in initializing integral values to zero ?
  19.  
  20. Yes. calloc will always initialize its region to all bits zero ... but
  21. if that region is not of integral type (e.g. if it is a pointer or a
  22. float), it can give access errors if accessed without further
  23. initialization because `all bits zero' may not be a valid bit
  24. pattern. Technically, I believe, because of interpretations that allow
  25. integral types to have holes which require to be fixed at some value,
  26. calloc may not be, strictly speaking, portable even for integral
  27. types: but I would usually not worry about things like that. The only
  28. place where I am absolutely sure that calloc does initialize to a
  29. known value, rather than a known possibly invalid bitpattern, is when
  30. initializing an array of character types.
  31.  
  32.    If so, why was a new function, which appears to have very limited used,
  33.    introduced in the first place ?
  34.  
  35. I would guess out of historical necessity. calloc is very rarely
  36. needed in portable code: it is best to avoid it.
  37.  
  38. Cheers
  39. Tanmoy
  40. --
  41. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  42. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  43. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  44. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  45. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  46. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  47.